package org.kafka.producer;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

public class kafkaProducer {

    public static void main(String[] args) throws IOException {
        InputStream in = System.in;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String msg = "";
        Properties props = new Properties();
        props.put("bootstrap.servers", "localhost:9093");
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        KafkaProducer<String, String> producer = new KafkaProducer<String, String>(props);
        while((msg = br.readLine())!="") {
            System.out.println("msg = [" + msg + "]");
            ProducerRecord producerRecord = new ProducerRecord("test-in", msg, msg);
            producer.send(producerRecord);
        }
    }
}
